import React from "react";
import { Modal, message } from 'antd';
import { useMappedState, useDispatch } from 'redux-react-hook';
import { set_delVisible } from '../../../../../store/action/house';
import api from "../../../../../api";

const DelMessage = (props:any) => {
    const state = useMappedState((state) => state.houseReducer);
    const dispatch = useDispatch();
    // 点击确定
    const handleOk = () => {
        dispatch(set_delVisible(false));
         // 调用删除接口
         api.delMessage({ id: state.delId }).then((res: any) => {
            if (res.success) {
                message.success('删除成功');
                // 重新渲染页面
                props.getMessageList();
            }
        })
    };
    // 点击取消
    const handleCancel = () => {
        dispatch(set_delVisible(false));
    };
    
    return (
        <>
            <Modal title="确认框" visible={state.delVisible} onOk={handleOk} onCancel={handleCancel}
                cancelText="取消"
                okText="确认"
            >
                <p>确定要删除吗</p>
            </Modal>
        </>
    )
};

export default DelMessage